package com.yuncheng.spcyApi.spcy;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.yuncheng.spcyApi.config.SpcyMinioUtils;
import com.yuncheng.spcyApi.constant.common.BusinessConstant;
import com.yuncheng.spcyApi.constant.common.SpcyConstant;
import com.yuncheng.spcyApi.entity.SpcyRsWjmb;
import com.yuncheng.spcyApi.entity.SpcySqsxWjjl;
import com.yuncheng.spcyApi.entity.SpcyZltxwjBasic;
import com.yuncheng.spcyApi.service.ISpcyRsWjmbService;
import com.yuncheng.spcyApi.service.ISpcySqsxWjjlService;
import com.yuncheng.spcyApi.service.ISpcyZltxwjBasicService;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import utils.Util;

import javax.annotation.Resource;
import java.io.File;
import java.util.List;

/**
 * @author hua
 */
@Api(tags = "文件备份迁移")
@RestController
@RequestMapping("/api/spzx-spcy/wjbfqy")
public class FileBakQyController {

    @Resource
    private SpcyMinioUtils spcyMinioUtils;

    @Resource
    private BusinessConstant businessConstant;

    @Resource
    private ISpcyZltxwjBasicService spcyZltxwjBasicService;

    @Resource
    private ISpcySqsxWjjlService spcySqsxWjjlService;

    @Resource
    private ISpcyRsWjmbService spcyRsWjmbService;

    /**
     * 备份迁移-质量体系文件
     */
    @GetMapping(value = "qybfByzltxwj")
    public void qybfByzltxwj(){
        List<SpcyZltxwjBasic> list = spcyZltxwjBasicService.list(new LambdaQueryWrapper<SpcyZltxwjBasic>()
                .isNotNull(SpcyZltxwjBasic::getFwjlj));

        for (SpcyZltxwjBasic z : list){
            String absUrl = businessConstant.UPLOAD_FILE_ROOT + z.getFwjlj();
            spcyMinioUtils.putFlagFile(z.getFwjlj(), new File(absUrl), Util.getWjHz(absUrl));
        }
    }

    /**
     * 备份迁移-用户签名
     */
    @GetMapping(value = "qybfByUserQm")
    public void qybfByUserQm(){
        List<SpcySqsxWjjl> list = spcySqsxWjjlService.list(new LambdaQueryWrapper<SpcySqsxWjjl>()
                .eq(SpcySqsxWjjl::getFwjlx1, BusinessConstant.USER_QM)
                .isNotNull(SpcySqsxWjjl::getFcflj));

        for (SpcySqsxWjjl z : list){
            String xdUrl = "/"+SpcyConstant.USERQM_FILE_BASE_URL + z.getFcflj();
            String absUrl = businessConstant.USER_QM_PATH + z.getFcflj();
            spcyMinioUtils.putFile(xdUrl, new File(absUrl), Util.getWjHz(absUrl));
        }
    }

    /**
     * 备份迁移-文件模板
     */
    @GetMapping(value = "qybfByWjmb")
    public void qybfByWjmb(){
        List<SpcyRsWjmb> list = spcyRsWjmbService.list(new LambdaQueryWrapper<SpcyRsWjmb>()
                .isNotNull(SpcyRsWjmb::getFcflj));

        for (SpcyRsWjmb z : list){
            String xdUrl = "/"+SpcyConstant.WJMB_FILE_BASE_URL + z.getFcflj();
            String absUrl = businessConstant.UPLOAD_WJMB_PATH + z.getFcflj();
            spcyMinioUtils.putFile(xdUrl, new File(absUrl), Util.getWjHz(absUrl));
        }
    }


}
